﻿/* 
	Patch that forces sending parameters names.
	Paste this piece of code in so-it loads after ExtJs/Sencha.
*/
(function () {
	// patch for extjs < 4.0
	(function () {
		var proto = Ext.direct.RemotingProvider.prototype;

		var getCallData = proto.getCallData;
		var connect = proto.connect;
		var mixin = {
			connect: function () {
				connect.apply(this, arguments);
				this.on('beforecall', function (p, t) { Ext.each(p.actions[t.action], function (m) { if (m.name == t.method) t.params = m.params }); }, this);
			},
			getCallData: function (t) {
				var d = getCallData.apply(this, arguments);

				d.params = t.params;
				if (Ext.isArray(d.data)) { // if arguments is array
					var data = {};
					for (var i = 0; i < d.data.length; i++) data[t.params[i]] = d.data[i]; // convert arguments to hashtable from array
					d.data = data;
				}
				return d;
			}
		};

		Ext.apply(proto, mixin);
	})();
})();